package cn.howxu.yichen_ovo.datagen;

import cn.howxu.yichen_ovo.YiChenOVO;
import cn.howxu.yichen_ovo.registry.DollRegistryEvent;
import cn.howxu.yichen_ovo.init.ModItems;
import net.minecraft.data.PackOutput;
import net.minecraft.world.item.Item;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.Objects;

public class ItemModelGenerator extends ItemModelProvider {
    public ItemModelGenerator(PackOutput output, ExistingFileHelper existingFileHelper) {
        super(output, YiChenOVO.MODID, existingFileHelper);
    }

    @Override
    protected void registerModels() {
        DollRegistryEvent.ITEMS.forEach(item -> {
            registerSpecialBlockItem(item,"block/doll/");
        });
        
        // 算法导论
        registerSpecialBlockItem(ModItems.ALBOOK.get());
        registerSpecialBlockItem(ModItems.WINE.get());

        ModItems.ITEMS.forEach(itemRegistryObject -> {
            basicItem(itemRegistryObject.get());
        });

        ModItems.PAINTS.forEach(item -> {
                    String path = Objects.requireNonNull(item.getId()).getPath();
                    singleTexture(path, modLoc("item/def_paint"),"layer0", modLoc("item/" + path));
                });
    }

    public void registerSpecialBlockItem(Item item){
        var key = ForgeRegistries.ITEMS.getKey(item);
        if (key == null) {
            return;
        }
        withExistingParent(key.getPath(), modLoc("block/" + key.getPath()));
    }

    public void registerSpecialBlockItem(Item item,String specialLoc){
        var key = ForgeRegistries.ITEMS.getKey(item);
        if (key == null) {
            return;
        }
        withExistingParent(key.getPath(), modLoc(specialLoc + key.getPath()));
    }
}
